/**
 *
 * @author Xinchro
 */

import java.awt.*;
import javax.swing.*;

public class GUI {
    JFrame frame;
    Timer timer;
    JTextArea timeDisplay;
    
    public GUI(Timer timer){
        this.timer = timer;
        startFrame();
        startFont();
        startTimeDisplay();
        moveToCenter();
    }
    Dimension dim = new Dimension(50,50);
    public void startFrame(){
        frame = new JFrame("Countdown");
        frame.setVisible(true);
        frame.setResizable(false);
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.setMinimumSize(dim);
        frame.setSize(50,50);
    }
    
    public void startFont(){
    }
    
    public void startTimeDisplay(){
        timeDisplay = new JTextArea();
        timeDisplay.setVisible(true);
        timeDisplay.setEditable(false);
        frame.setMinimumSize(dim);
        timeDisplay.setSize(50,50);
        frame.add(timeDisplay);
    }
    
    public void setTime(int time){
        String dispTime = "" + time;
        timeDisplay.setText(dispTime);
    }
    
    public void moveToCenter(){
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

        int w = frame.getSize().width;
        int h = frame.getSize().height;
        int x = (dim.width - w) / 2;
        int y = (dim.height - h) / 2;

        frame.setLocation(x, y);
        frame.setFocusable(true);
        frame.addKeyListener(timer.input);
        frame.addMouseListener(timer.input);
        frame.addMouseWheelListener(timer.input);
    }
}
